import request from '@/utils/request'

// 查询题库管理列表
export function listQuestionBank(query) {
  return request({
    url: '/fk/question_bank/list',
    method: 'get',
    params: query
  })
}

// 查询题库管理详细
export function getQuestionBank(id) {
  return request({
    url: '/fk/question_bank/' + id,
    method: 'get'
  })
}

// 新增题库管理
export function addQuestionBank(data) {
  return request({
    url: '/fk/question_bank',
    method: 'post',
    data: data
  })
}

// 修改题库管理
export function updateQuestionBank(data) {
  return request({
    url: '/fk/question_bank',
    method: 'put',
    data: data
  })
}

// 删除题库管理
export function delQuestionBank(id) {
  return request({
    url: '/fk/question_bank/' + id,
    method: 'delete'
  })
}

// 导出题库管理
export function exportQuestionBank(query) {
  return request({
    url: '/fk/question_bank/export',
    method: 'post',
    data: query
  })
}

// 根据题库ID查询相关联的题目信息
export function getQuestionsByBankId(bankId) {
  return request({
    url: '/fk/question_bank/questions/' + bankId,
    method: 'get'
  })
}

// 批量添加题库题目关联
export function batchAddQuestions(data) {
  return request({
    url: '/fk/question_bank/batchAddQuestions',
    method: 'post',
    data: data
  })
}

// 批量删除题库题目关联
export function batchRemoveQuestions(data) {
  return request({
    url: '/fk/question_bank/batchRemoveQuestions',
    method: 'post',
    data: data
  })
}

// 根据题库ID删除所有关联的题目
export function removeAllQuestionsByBankId(bankId) {
  return request({
    url: '/fk/question_bank/questions/' + bankId,
    method: 'delete'
  })
}

// 查询题库中未关联的题目
export function getUnlinkedQuestions(bankId, params) {
  return request({
    url: '/fk/question_bank/unlinkedQuestions/' + bankId,
    method: 'get',
    params: params
  })
}

// 章节练习查询，vue端，用id查
export function getQuestionBankChapter(id) {
  return request({
    url: '/fk/question_bank/chapterById/' + id,
    method: 'get'
  })
}

// 根据科目ID查询题库列表
export function getQuestionBankBySubjectId(subjectId, params = {}) {
  return request({
    url: '/fk/question_bank/listBySubjectId/' + subjectId,
    method: 'get',
    params: params
  })
}

// 根据科目ID查询题库列表（不分页）
export function getQuestionBankBySubjectIdNoPage(subjectId) {
  return request({
    url: '/fk/question_bank/listBySubjectIdNoPage/' + subjectId,
    method: 'get'
  })
}

// 检查用户是否购买指定题库
export function checkUserQuestionBankPurchase(userId, questionBankId) {
  return request({
    url: '/fk/question_bank/checkUserPurchase',
    method: 'get',
    params: {
      userId,
      questionBankId
    }
  })
}